import instance from '../instance.js'

// 用户地址相关API
export const userAddressAPI = {
    // 添加用户地址
    addAddress(addressData) {
        return instance.post('/user/address', addressData)
    },

    // 设置默认用户地址
    setDefaultAddress(id) {
        return instance.patch(`/user/address/${id}/default`)
    },

    // 获取用户全部收货地址
    getAddressList(pageNo, pageSize) {
        const params = {}
        if (pageNo !== undefined) params.pageNo = pageNo
        if (pageSize !== undefined) params.pageSize = pageSize
        return instance.get('/user/address/list', { params })
    },

    // 根据ID获取用户地址
    getAddressById(id) {
        return instance.get(`/user/address/${id}`)
    },

    // 更新用户地址
    updateAddress(id, addressData) {
        return instance.put(`/user/address/${id}`, addressData)
    },

    // 删除用户地址
    deleteAddress(id) {
        return instance.delete(`/user/address/${id}`)
    }
}

export default userAddressAPI